package com.bytedance.article.common.a.a;

import android.os.Handler;
import android.os.HandlerThread;

import com.bytedance.framwork.core.monitor.HttpResponseException;
import com.bytedance.framwork.core.monitor.MonitorNetUtil$CompressType;

import org.json.JSONObject;

import java.util.LinkedList;

import inline.NetworkDemo;

public class c implements com.bytedance.framwork.core.monitor.c.c$c {
    Handler a;
    Runnable b;
    private static volatile c c;
    private HandlerThread d;
    private static final LinkedList e;
    private static volatile boolean f;
    private volatile long g;
    private volatile long h;
    private JSONObject i;

    static {
        e = new LinkedList();
    }

    private c() {

        this.d = new HandlerThread("caton_dump_stack");
        this.b = new d(this);
        this.d.start();
        this.a = new Handler(this.d.getLooper());
        com.bytedance.framwork.core.monitor.c.a(this);
    }

    static c a() {
        if (c == null) {
            Class v1 = c.class;
            synchronized (v1) {
                if (c == null) {
                    c = new c();
                }
            }
        }
        return c;
    }

    static long a(c arg1, long arg2) {
        arg1.h = arg2;
        return arg2;
    }

    static JSONObject a(c arg0, JSONObject arg1) {
        arg0.i = arg1;
        return arg1;
    }

    static void a(c arg0) {
        arg0.f();
    }

    static void a(c arg6, String arg7, String arg8) {
        try {
            if (com.bytedance.framwork.core.monitor.c.j() == null) {
                return;
            }

            com.bytedance.framwork.core.monitor.c.j();
            NetworkDemo.a(com.bytedance.framwork.core.monitor.c.d(arg7), arg8.getBytes(), MonitorNetUtil$CompressType.GZIP, "application/json; charset=utf-8", true);
        } catch (Throwable v0) {
            int v1 = -1;
            int v0_1 = (v0 instanceof HttpResponseException) ? ((HttpResponseException) v0).getStatusCode() : v1;
            if (v0_1 < 500) {
                return;
            }

            if (v0_1 > 600) {
                return;
            }

            arg6.g = System.currentTimeMillis();
            c.f = true;
        }
    }

    static long b() {
        long v0 = com.bytedance.framwork.core.monitor.c.j() == null || com.bytedance.framwork.core.monitor.c.j().l < 20 ? 500 : com.bytedance.framwork.core.monitor.c.j().l;
        return v0;
    }

    static JSONObject b(c arg1) {
        return arg1.i;
    }

    public final void c() {
        long v0 = System.currentTimeMillis();
        if ((c.f) && v0 - this.g > 1800000) {
            c.f = false;
        }

        if (v0 - this.h > 600000) {
            this.f();
        }
    }

    static boolean d() {
        return c.f;
    }

    static LinkedList e() {
        return c.e;
    }

    private void f() {
        com.bytedance.frameworks.core.thread.c.a();
        com.bytedance.frameworks.core.thread.c.a(new e(this));
    }
}

